package com.abe.bathsystem.widget.dialog;


import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;

import com.abe.bathsystem.base.ManagerLocalData;
import com.abe.bathsystem.widget.OnOperateListener;
import com.abe.libcore.utils.normal.ToastUtils;

import net.yet.campusdev.R;

public class SettingUrlDialog extends BaseDialog {

    private DialogContract.OnSetServiceUrlListener listener;

    public SettingUrlDialog(@NonNull Context context) {
        super(context);
    }

    public SettingUrlDialog(@NonNull Context context, OnOperateListener operateListener) {
        super(context, operateListener);
    }

    public void setListener(DialogContract.OnSetServiceUrlListener listener) {
        this.listener = listener;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.item_view_v3_set_common);
        final EditText item_edit_value = findViewById(R.id.item_edit_value);
        item_edit_value.setHint(R.string.hint_input_set_url);
        item_edit_value.setText(ManagerLocalData.getServiceUrl());
        ((Button) findViewById(R.id.item_btn_setting)).setText(R.string.setting);
        findViewById(R.id.item_btn_setting).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String url = item_edit_value.getText().toString().trim();
                if (TextUtils.isEmpty(url)) {
                    ToastUtils.show(R.string.hint_input_set_url);
                    return;
                }
                if (listener != null) {
                    listener.onSetUrl(url);
                } else {
                    ToastUtils.show("请绑定回调监听");
                }
                dismiss();
            }
        });
    }
}
